package com.probox.common.security.entity;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.probox.common.core.annotation.CanNotHaveBlank;
import com.probox.common.core.annotation.Excel;
import com.probox.common.core.utils.SplitUtils;
import com.probox.common.core.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import java.io.Serializable;
import java.util.Date;

/**
 * 发布内容对象 publish_content
 *
 * @author usoft
 * @date 2022-06-06
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("publish_content")
@ApiModel(description = "发布内容")
public class PublishContent implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 内容ID
     */
    //默认主键自增
    @TableId(value = "content_id", type = IdType.AUTO)
    private Long contentId;


    /**
     * 会员ID
     */
    @Excel(name = "会员ID")
    @ApiModelProperty(value = "会员ID")
    private Long customerId;

    /**
     * 内容标题
     */
    @Excel(name = "内容标题")
    @ApiModelProperty(value = "内容标题")
    @CanNotHaveBlank(message = "标题", max = 50)
    private String contentTitle;

    /**
     * 内容图片/视频
     */
    @Excel(name = "内容图片/视频")
    @ApiModelProperty(value = "内容图片/视频")
    @Length(max = 2000, message = "内容图片/视频不能超过2000")
    private String contentResource;

    public String getContentResourceStr() {
        if (StringUtils.isNotEmpty(contentResource)) {
            return SplitUtils.isVideo(contentResource);

        }
        return "";
    }

    public String[] getContentResourceImg() {
        if (ObjectUtil.isEmpty(contentResource)) {
            return new String[0];
        }
        return contentResource.split(",");
    }

    public String getContentResourceType() {
        if (StringUtils.isNotEmpty(contentResource)) {
            return SplitUtils.isVideoType(contentResource);
        }
        return "";
    }


    /**
     * 内容描述
     */
    @Excel(name = "内容描述")
    @ApiModelProperty(value = "内容描述")
    @Length(max = 2000, message = "描述不能超过2000")
    private String contentDesc;

    /**
     * 标签（用逗号分割）
     */
    @Excel(name = "标签", readConverterExp = "用=逗号分割")
    @ApiModelProperty(value = "标签")
    private String tags;

    public String getAuditStatusStr() {
        if ("0".equals(auditStatus)) {
            return "待审核";
        }
        if ("1".equals(auditStatus)) {
            return "上架";
        }
        if ("-1".equals(auditStatus)) {
            return "下架";
        }
        return "";
    }

    /**
     * 地点ID
     */
    @Excel(name = "地点ID")
    @ApiModelProperty(value = "地点ID")
    private Long locationId;

    /**
     * 维度
     */
    @Excel(name = "维度")
    @ApiModelProperty(value = "维度")
    private String locationLat;

    /**
     * 经度
     */
    @Excel(name = "经度")
    @ApiModelProperty(value = "经度")
    private String locationLong;

    /**
     * 地点名字
     */
    @Excel(name = "地点名字")
    @ApiModelProperty(value = "地点名字")
    private String locationName;


    /**
     * 详细地址
     */
    @Excel(name = "详细地址")
    @ApiModelProperty(value = "详细地址")
    private String locationDetailAddress;

    /**
     * 城市
     */
    @Excel(name = "城市")
    @ApiModelProperty(value = "城市")
    private String locationCity;

    /**
     * 区域
     */
    @Excel(name = "区域")
    @ApiModelProperty(value = "区域")
    private String locationArea;

    /**
     * 是否推荐（0-不推荐/1-推荐）
     */
    @Excel(name = "是否推荐", readConverterExp = "0=-不推荐/1-推荐")
    @ApiModelProperty(value = "是否推荐")
    private String isRecommend;

    /**
     * 数据状态（0-草稿/1-发布）
     */
    @Excel(name = "数据状态", readConverterExp = "0=-草稿/1-发布")
    @ApiModelProperty(value = "数据状态")
    private String dataStatus;

    /**
     * 审核状态（0-申请发布/1-发布通过/-1驳回）
     */
    @Excel(name = "审核状态", readConverterExp = "0=-申请发布/1-发布通过/-1驳回")
    @ApiModelProperty(value = "审核状态")
    private String auditStatus;

    /**
     * 审核描述
     */
    @Excel(name = "审核描述")
    @ApiModelProperty(value = "审核描述")
    private String auditMsg;

    /**
     * 创建人
     */
    @Excel(name = "创建人")
    @ApiModelProperty(value = "创建人")
    private Long createUser;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 创建人名称
     */
    @Excel(name = "创建人名称")
    @ApiModelProperty(value = "创建人名称")
    private String createName;

    /**
     * 修改人
     */
    @Excel(name = "修改人")
    @ApiModelProperty(value = "修改人")
    private Long updateUser;

    /**
     * 修改时间
     */
    private Date updateTime;

    /**
     * 修改人名称
     */
    @Excel(name = "修改人名称")
    @ApiModelProperty(value = "修改人名称")
    private String updateName;

    /**
     * 审核人
     */
    @Excel(name = "审核人")
    @ApiModelProperty(value = "审核人")
    private Long auditUser;

    /**
     * 审核时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "审核时间", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty(value = "审核时间")
    private Date auditTime;

    /**
     * 审核人名称
     */
    @Excel(name = "审核人名称")
    @ApiModelProperty(value = "审核人名称")
    private String auditName;

    /**
     * 点赞数
     */
    @Excel(name = "点赞数")
    @ApiModelProperty(value = "点赞数")
    private Long zanCount;

    /**
     * 收藏数
     */
    @Excel(name = "收藏数")
    @ApiModelProperty(value = "收藏数")
    private Long collectCount;


    @TableField(exist = false)
    private String customerName;

    @TableField(exist = false)
    private String phone;

    public String getPhoneStr() {
        if (ObjectUtil.isEmpty(phone)) {
            return "";
        }
        return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }

    @TableField(exist = false)
    private String sTime;

    @TableField(exist = false)
    private String eTime;

    @TableField(exist = false)
    private String type;

    @TableField(exist = false)
    private String tionLat;

    @TableField(exist = false)
    private String tionLong;
}
